package com.cat.dynamicPlanning02;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/maximum-balanced-shipments/description/?envType=problem-list-v2&envId=dynamic-programming
 * @create 2025/10/1 20:09
 * @since JDK17
 */

public class Solution11 {
    public int maxBalancedShipments(int[] weight) {
        int n = weight.length, top = 0, ans = 0;
        int[] stack = new int[n];
        for (int i = 0; i < n; i++) {
            boolean flag = false;
            if (top > 0 && weight[i] < weight[stack[top - 1]]) {    //
                top = 0;
                ans++;
            } else {
                stack[top++] = i;
            }
        }

        return ans;
    }
}
